{include file='public/meta' }
	<title>邮件配置 - 木鱼内容管理系统</title>

</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-header">邮箱设置</div>
              <div class="layui-card-body">
                <form class="layui-form" action="" id="form-system-base">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SMTP服务器</label>
                        <div class="layui-input-block">
                          <input type="text" name="smtp" value="{$sms.smtp}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SMTP 端口</label>
                        <div class="layui-input-block">
                          <input type="text" name="sll" value="{$sms.sll}"  lay-verify="number" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱帐号</label>
                        <div class="layui-input-block">
                          <input type="text" name="email" id="email" value="{$sms.email}"  lay-verify="email" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱密码</label>
                        <div class="layui-input-inline">
                          <input type="password" name="emailpaswsd" value="{$sms.emailpaswsd}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">请填写授权码</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">测试邮箱</label>
                        <div class="layui-input-inline">
                          <input type="text" name="ceemail" id="ceemail" value=""  lay-verify="email" placeholder="请输入测试邮箱" autocomplete="off" class="layui-input">
                        </div>
                        
                          <div class="layui-input-inline"><button type="button" id="test" class="layui-btn layui-btn-primary layui-border-green">发送测试</button></div>
                    </div>
                    <input type="hidden" name="id" id="id" value="{$sms.id}">
                </form>
              </div>
            </div>
        </div>
    </div>
    
     <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-header">短信配置</div>
              <div class="layui-card-body">
                <form class="layui-form" action="" id="sms">
                    <div class="layui-form-item">
                        <label class="layui-form-label">短信宝账号</label>
                        <div class="layui-input-block">
                          <input type="text" name="smsbao_account" value="{$sms.smsbao_account}"  lay-verify="required" placeholder="请输入短信宝账号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">短信宝密码</label>
                        <div class="layui-input-block">
                          <input type="password" name="smsbao_password" value="{$sms.smsbao_password}"  lay-verify="number" placeholder="请输入短信宝密码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">测试手机</label>
                        <div class="layui-input-inline">
                          <input type="text" name="smsbao_phone" id="smsbao_phone" value=""  lay-verify="email" placeholder="请输入测试手机号码" autocomplete="off" class="layui-input">
                        </div>
                          <div class="layui-input-inline"><button type="button" id="testSmsbao" class="layui-btn layui-btn-primary layui-border-green">发送测试</button></div>
                    </div>
                </form>
              </div>
            </div>
        </div>
    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                          <button class="layui-btn" type="button" id="btn">确认保存</button>
                        </div>
                      </div>
</div>
{include file='public/footer' }

	<!--请在下方写此页面业务相关的脚本-->

	<script type="text/javascript">
  layui.config({
    base: '__ADMINST__layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['form','element'],function(){
      var $ = layui.$
    ,element = layui.element//Tab的切换功能，切换事件监听等，需要依赖element模块
    ,form = layui.form ;
    //状态监听
  });

	//表单验证，提交
	//表单验证，提交
	$("#btn").on("click",function(){
		var email=$('#form-system-base').serializeArray();
		var smsbao = $('#sms').serializeArray();
		Data = email.concat(smsbao);
		 $.post("{:url('Sms/edit')}",Data,function(data){
		     if(data.code == 1){
         		    layer.msg(data.msg,{time:2000},function(){
        			if(data.url) location.href = data.url;
        		});
		     }else{
		         layer.msg(data.msg,{time:2000});
		     }

		 });
	});
			
			
	//发送测试邮件
	$("#test").on("click",function(){
	    email = $('#email').val();
	    testemail = $('#ceemail').val();
		var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		var isok = reg.test(email);
		var isoks = reg.test(testemail);
		if(!isok) {
			layer.msg('邮箱格式不正确，请修改!',{icon:5,time:2000},function(){
			document.getElementById("ceemail").focus();
			});
				
		}else{
		    if(!isoks){
    			layer.msg('邮箱格式不正确，请修改!',{icon:5,time:2000},function(){
			    document.getElementById("email").focus();
			});
		    }else{
		        data = $('#form-system-base').serializeArray();
		        $.post("{:url('Sms/sendEmail')}",data,function(data){
    		    if(data.code == 1){
            		layer.msg(data.msg,{icon:6,time:5000},function(){
            			location.href = data.url;
            		});
    		    }else{
    		        layer.msg(data.msg,{icon:2,time:5000});
    		    }
    		 });
		    }
		 }
		});
		
		//测试发送短信
		$('#testSmsbao').on('click',function(){
		        data = $('#sms').serializeArray();
		        $.post("{:url('Sms/testSmsbao')}",data,function(data){
    		    if(data.code == 1){
            		layer.msg(data.msg,{icon:6,time:5000},function(){
            			location.href = data.url;
            		});
    		    }else{
    		        layer.msg(data.msg,{icon:2,time:5000});
    		    }
    		 });
		});

	</script>
	<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
